<?php

class Account {
        private $id;
        private $adres;
        private $limiet;
        private $naam;
        private $rekeningnummer;
        private $saldo;
        private $woonplaats;
        
        public function getId() {
                return $this->id;
        }

        public function setId($id) {
                $this->id = $id;
        }
        
        public function getAdres() {
                return $this->adres;
        }

        public function setAdres($adres) {
                $this->adres = $adres;
        }

        public function getLimiet() {
                return $this->limiet;
        }

        public function setLimiet($limiet) {
                $this->limiet = $limiet;
        }

        public function getNaam() {
                return $this->naam;
        }

        public function setNaam($naam) {
                $this->naam = $naam;
        }

        public function getRekeningnummer() {
                return $this->rekeningnummer;
        }

        public function setRekeningnummer($rekeningnummer) {
                $this->rekeningnummer = $rekeningnummer;
        }

        public function getSaldo() {
                return $this->saldo;
        }

        public function setSaldo($saldo) {
                $this->saldo = $saldo;
        }

        public function getWoonplaats() {
                return $this->woonplaats;
        }

        public function setWoonplaats($woonplaats) {
                $this->woonplaats = $woonplaats;
        }
}

class Transaction {
        private $ID;
        private $bedrag;
        private $datum;
        private $ontvanger_ID;
        private $verzender_ID;
        
        public function getID() {
                return $this->ID;
        }
        
        public function getBedrag() {
                return $this->bedrag;
        }

        public function setBedrag($bedrag) {
                $this->bedrag = $bedrag;
        }

        public function getDatum() {
                return $this->datum;
        }

        public function getOntvanger_ID() {
                return $this->ontvanger_ID;
        }

        public function setOntvanger_ID($ontvanger_ID) {
                $this->ontvanger_ID = $ontvanger_ID;
        }

        public function getVerzender_ID() {
                return $this->verzender_ID;
        }

        public function setVerzender_ID($verzender_ID) {
                $this->verzender_ID = $verzender_ID;
        }
}

if(isset($_POST['action'])){
        try {
                //Client opzetten, locatie van WSDL geven.
                $client = new SoapClient("http://127.0.0.1:8080/week2_opdracht2/JavabankResourceService?wsdl", array( 
                        'trace' => 1,
                        'classmap' => array(
                            'account' => 'Account',
                            'transaction' => 'Transaction',
                            )
                    ));
        
                switch ($_POST['action']){
                        case 'transfer':
                                //Functie aanroepen. Parameter als assoc. array meegeven
                                $result = $client->transfer(array(
                                    "arg0"=>$_POST['PARAMtransfer0'],
                                    "arg1"=>$_POST['PARAMtransfer1'],
                                    "arg2"=>$_POST['PARAMtransfer2'],
                                    ));
                                break;
                        case 'alterAccount':
                                //Functie aanroepen. Parameter als assoc. array meegeven
                                $result = $client->getAccount(array("arg0"=>$_POST['PARAMalterAccount0']));
                                
                                print_r($result->return);
                                
                                $account = $result->return;
                                $account->setId($_POST['PARAMalterAccount1']);
                                $account->setNaam($_POST['PARAMalterAccount2']);
                                $account->setAdres($_POST['PARAMalterAccount3']);
                                $account->setWoonplaats($_POST['PARAMalterAccount4']);
                                $account->setSaldo($_POST['PARAMalterAccount5']);
                                $account->setLimiet($_POST['PARAMalterAccount6']);
                                $account->setRekeningnummer('7406466');
                                
                                print_r($account);
                                
                                //Functie aanroepen. Parameter als assoc. array meegeven
                                $result = $client->alterAccount(array("arg0"=>$account));
                                break;
                        case 'getTransactions':
                                //Functie aanroepen. Parameter als assoc. array meegeven
                                $result = $client->getTransactions(array("arg0"=>$_POST['PARAMgetTransactions0'], "arg1"=>$_POST['PARAMgetTransactions1']));
                                break;
                        case 'getAccount':
                                //Functie aanroepen. Parameter als assoc. array meegeven
                                $result = $client->getAccount(array("arg0"=>$_POST['PARAMgetAccount0']));
                                break;
                        case 'openAccount':
                                $account = new Account();
                                $account->setNaam($_POST['PARAMopenAccount0']);
                                $account->setAdres($_POST['PARAMopenAccount1']);
                                $account->setWoonplaats($_POST['PARAMopenAccount2']);
                                $account->setSaldo($_POST['PARAMopenAccount3']);
                                $account->setLimiet($_POST['PARAMopenAccount4']);
                                
                                //Functie aanroepen. Parameter als assoc. array meegeven
                                $result = $client->openAccount(array("arg0"=>$account));
                                break;
                }                
        } catch (SoapFault $exception) {
                //Oopz, er is iets mis gegaan
                echo '<pre>';
                echo $exception;
                echo '</pre>';

                print_r(htmlentities($client->__getLastRequest()));  

                exit;
        }
        
        ?>
        <h1>
                Request
        </h1>
        <hr />
        <?php
        
        print_r(htmlentities($client->__getLastRequest()));     
        
        ?>
        <h1>
                Response:
        </h1>
        <hr />
        <?php
        
        echo '<pre>';
        print_r($result);
        echo '</pre>';
}else{
?>
<!DOCTYPE html>
<HTML>
        <HEAD>
                <TITLE>
                        JavabankResourceService Web Service Tester
                </TITLE>
        </HEAD>
        <BODY>
                <H1>
                        JavabankResourceService Web Service Tester
                </H1>
                <br>
                This form will allow you to test your web service implementation (<A HREF="http://127.0.0.1:8080/week2_opdracht2/JavabankResourceService?WSDL">WSDL File</A>)
                <hr>
                To invoke an operation, fill the method parameter(s) input boxes and click on the button labeled with the method name.
                <H3>Methods :</H3>
                <FORM METHOD="POST">
                        public abstract boolean com.javabank.ws.resource.JavabankResource.transfer(float,java.lang.String,java.lang.String)
                        <BR>
                        <INPUT TYPE=SUBMIT NAME=action value=transfer> (<INPUT TYPE=TEXT NAME=PARAMtransfer0>,<INPUT TYPE=TEXT NAME=PARAMtransfer1>,<INPUT TYPE=TEXT NAME=PARAMtransfer2>)
                        <BR>
                        <HR>
                </FORM>
                <FORM METHOD="POST">public abstract void com.javabank.ws.resource.JavabankResource.alterAccount(rekeningnummer, id, naam, adres, woonplaats, saldo, limiet)
                        <BR>
                        <INPUT TYPE=SUBMIT NAME=action value=alterAccount> (
                                <INPUT TYPE=TEXT NAME=PARAMalterAccount0>,
                                <INPUT TYPE=TEXT NAME=PARAMalterAccount1>,
                                <INPUT TYPE=TEXT NAME=PARAMalterAccount2>,
                                <INPUT TYPE=TEXT NAME=PARAMalterAccount3>,
                                <INPUT TYPE=TEXT NAME=PARAMalterAccount4>,
                                <INPUT TYPE=TEXT NAME=PARAMalterAccount5>,
                                <INPUT TYPE=TEXT NAME=PARAMalterAccount6>
                        )
                        <BR>
                        <HR>
                </FORM>
                <FORM METHOD="POST">public abstract java.util.List com.javabank.ws.resource.JavabankResource.getTransactions(String rekeningnummer, String datum)
                        <BR>
                        <INPUT TYPE=SUBMIT NAME=action value=getTransactions> (<INPUT TYPE=TEXT NAME=PARAMgetTransactions0>,<INPUT TYPE=TEXT NAME=PARAMgetTransactions1>)
                        <BR>
                        <HR>
                </FORM>
                <FORM METHOD="POST">public abstract com.javabank.ws.resource.Account com.javabank.ws.resource.JavabankResource.getAccount(rekeningnummer)
                        <BR>
                        <INPUT TYPE=SUBMIT NAME=action value=getAccount> (<INPUT TYPE=TEXT NAME=PARAMgetAccount0>)
                        <BR>
                        <HR>
                </FORM>
                <FORM METHOD="POST">public abstract void com.javabank.ws.resource.JavabankResource.openAccount(naam, adres, woonplaats, saldo, limiet)
                        <BR>
                        <INPUT TYPE=SUBMIT NAME=action value=openAccount> (
                                <INPUT TYPE=TEXT NAME=PARAMopenAccount0>,
                                <INPUT TYPE=TEXT NAME=PARAMopenAccount1>,
                                <INPUT TYPE=TEXT NAME=PARAMopenAccount2>,
                                <INPUT TYPE=TEXT NAME=PARAMopenAccount3>,
                                <INPUT TYPE=TEXT NAME=PARAMopenAccount4>                             
                        )
                        <BR>
                        <HR>
                </FORM>
        </BODY>
</HTML>
<?php
}
?>